import router from './router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import store from './store'
const whiteList = ['/login', '/register', '/404']
router.beforeEach((to, from, next) => {
  console.log('前置守卫', to, from)
  NProgress.start()
  if (store.state.user.token) {
    if (whiteList.includes(to.path)) {
      next('/')

      NProgress.done()
    } else {
      store.dispatch('user/getUserInfoAction')
      next()
    }
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
      NProgress.done()
    }
  }
})
router.afterEach(() => {
  NProgress.done()
  console.log('后置守卫')
})
